<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <!--导入样式-->
    <link rel="stylesheet" th:href="@{/css/register.css}">
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css"
          th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}">
    </script>
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<form name="registerForm" id="registerForm" method="post" style="width:50%; margin:0
auto">
    <h1 align="center">注&emsp;&emsp;册</h1>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <p>请输入手机号：</p>
            </div>
            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control"
                       type="text" placeholder="手机号码" required="true"
                       minlength="11" maxlength="11"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <p>请输入用户名：</p>
            </div>
            <div class="col-md-5">
                <input id="nickname" name="nickname" class="form-control"
                       type="text" placeholder="用户名" required="true"
                       minlength="1" maxlength="50"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <p>请输入收货地址：</p>
            </div>
            <div class="col-md-5">
                <input id="address" name="address" class="form-control"
                       type="text" placeholder="收货地址" required="true"
                       minlength="1" maxlength="150"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <p>请输入密码：</p>
            </div>
            <div class="col-md-5">
                <input id="password" name="password" class="form-control"
                       type="password" placeholder="密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <div class="col-md-5">
                <p>请确认密码：</p>
            </div>
            <div class="col-md-5">
                <input id="password2" name="password2" class="form-control"
                       type="password" placeholder="确认密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="reset"
                    onclick="reset()">重置
            </button>
        </div>
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="submit"
                    onclick="register()">注册
            </button>
        </div>
    </div>
    <p>
        已有账号？<a href="/login/toLogin">请登录</a>
    </p>
</form>
</body>
<script>
    function register(){
        /*注册校验*/
        $("#registerForm").validate({
            submitHandler: function (form) {
                /*校验成功，调用doregister*/
                doregister();
            }
        });
    }
    function doregister(){
        g_showLoading();/*加载图标转圈圈*/
        $.ajax({
            url: "/register/doregister",/*调用后端接口*/
            type: "GET",
            data: {
                mobile: $("#mobile").val(),
                password:$("#password").val(),
                password2:$("#password2").val(),
                nickname:$("#nickname").val(),
                address:$("#address").val()
            },
            success: function (data) {
                layer.closeAll();
                //console.log(data)
                if (data.code == 200) {
                    //render(data.obj);
                    layer.msg("成功");
                    window.location.href = "/login/toLogin";
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</html>